package com.awspaas.user.apps.cpq.event;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.InterruptListener;
import com.actionsoft.bpms.bpmn.engine.listener.ListenerConst;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.exception.BPMNError;

public class ModuleFormBeforeSave extends InterruptListener{

	public ModuleFormBeforeSave() {
		setDescription("模块创建后，保存前校验模块编码是否重复。");
	}

	@Override
	public boolean execute(ProcessExecutionContext pec) throws Exception {
		try {
			String bindId=pec.getProcessInstance().getId();
			//BO表名
	        String boName = pec.getParameterOfString(ListenerConst.FORM_EVENT_PARAM_BONAME);
	        if(boName.equals("BO_EU_CPQ_MODULE_MSG")) {
	        	BO formData = (BO) pec.getParameter(ListenerConst.FORM_EVENT_PARAM_FORMDATA);
	        	String bm=formData.getString("MKBM");
	        	String sql="select  * from BO_EU_CPQ_MODULE_MSG where MKBM=? and STATUS='启用' and BINDID!='"+bindId+"'";
	        	RowMap map=DBSql.getMap(sql, new Object[] {bm});
	        	if(null!=map) {
	        		throw new BPMNError("003", "该编码"+bm+",在模块清单台账中已存在，请重新输入编码。");
	        	}
	        }
			return true;
		} catch (Exception e) {
			throw e;
		}
		
	}

}